package com.VitalFit.repository;

import com.VitalFit.model.entity.Appointment;
import com.VitalFit.model.entity.Trainer;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface AppointmentRepository extends JpaRepository<Appointment, Long> {

    Page<Appointment> findAppointmentByCustomerId(Long customer_id, Pageable pageable);

    @Query("SELECT a FROM Appointment a WHERE a.trainer = :trainer AND (:startDateTime < a.endDateTime AND :endDateTime > a.startDateTime)")
    List<Appointment> findOverlappingAppointments(@Param("trainer") Trainer trainer,
                                                  @Param("startDateTime") LocalDateTime startDateTime,
                                                  @Param("endDateTime") LocalDateTime endDateTime);

}
